﻿using AdminSystem.Application;
using AdminSystem.Application.Addresss;
using AdminSystem.Application.Addresss.Dto;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace AdminSystem.WebApi.Controllers
{
    /// <summary>
    /// 控制器用于处理地址相关的API请求。
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = "v1")]
    public class AddressController : ControllerBase
    {
        private readonly IAddressService addressService;

        /// <summary>
        /// 初始化 AddressController 类的新实例。
        /// </summary>
        /// <param name="addressService">地址服务接口的实例。</param>
        public AddressController(IAddressService addressService)
        {
            this.addressService = addressService;
        }

        /// <summary>
        /// 添加地址
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> CreateAsync(CreateUpdateAddressDto dto)
        {
            return Ok(await addressService.CreateAsync(dto));
        }

        /// <summary>
        /// 查询第一个地址
        /// </summary>
        /// <returns>第一个地址的结果</returns>
        [HttpGet]
        public async Task<IActionResult> QueryFirstAsync([FromQuery]SearchAddressDto searchAddressDto, [FromQuery]PageDto pageDto)
        {
            return Ok(await addressService.PageAsync(searchAddressDto, pageDto));
        }

        /// <summary>
        /// CI/CD测试
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        public IActionResult Test()
        {
            return Ok();
        }
    }
}
